
import { mapSet } from '@/config'
import * as ol from '../openLayer'
import { createMarksStyle } from './style'
import { locationOptionDefaultConfig } from './config'
import { deepAssign } from '@/utils/tools/deepAssign'
/**
 * OlLocationMark 定位 类，
  }
 */
/**
 * marks 样式参考marksStyle 样式配置项
 */

export default class OlLocationMark {
  constructor (_map, _config) {
    this.map = _map
    this.options = deepAssign(locationOptionDefaultConfig, _config) //  配置项
    this.coordinatePointMark = null
    this.center = this.map.getView().getCenter() //  地图中心点
    this.setLocationMark(this.center)
  }

  /**
   * 更新OlLocationMark，（待开发）
   */
  updateOlLocationMark (_map, _config) {
    this.map = _map
    this.options = deepAssign(locationOptionDefaultConfig, _config) //  配置项
  }

  /**
   * 设置定位点样式
   * @param {*} point
   */
  setLocationMark (point) {
    if (this.coordinatePointMark) {
      this.map.removeLayer(this.coordinatePointMark)
      this.coordinatePointMark = null
    }
    let coordinatePointFeature = new ol.Feature({
      geometry: new ol.Point(point)
    })
    coordinatePointFeature.setStyle(
      this.setSelectStyle()
    )
    const vectorSource = new ol.VectorSource({
      features: [coordinatePointFeature]
    })

    this.coordinatePointMark = new ol.VectorLayer({
      source: vectorSource,
      className: this.options.layerProperties.id,
      properties: this.options.layerProperties
    })
    this.map.addLayer(this.coordinatePointMark)
  }

  /**
   * 设置marks 样式
   * @param {*} feature
   * @returns
   */
  setSelectStyle () {
    let markerStyle = createMarksStyle(this.options.layerStyle)
    return markerStyle
  }
}
